package com.zm.xiaohashu.biz.context.interceptor;


import com.zm.constant.GlobalConstants;
import com.zm.xiaohashu.biz.context.utils.LoginUserContextHolder;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

@Slf4j
public class FeignRequestInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Long userId = LoginUserContextHolder.getUserId();
        if (Objects.nonNull(userId)) {
            log.info("########## feign 请求设置请求头 userId: {}", userId);
            requestTemplate.header(GlobalConstants.USER_ID, String.valueOf(userId));
        }
    }
}
